/*
 * $Id: string_word.c,v 1.1 2007-03-22 11:31:38 bacon Exp $
 */

#if defined(__MSTRING)
#include <xp/bas/mstring.h>
#elif defined(__WSTRING)
#include <xp/bas/mstring.h>
#else
#include <xp/bas/string.h>
#endif

#include <xp/bas/ctype.h>

const xp_char_t* xp_strxword (
	const xp_char_t* str, xp_size_t len, const xp_char_t* word)
{
        const xp_char_t* ptr = str;
        const xp_char_t* end = str + len;
        const xp_char_t* s;

        do
        {
                while (ptr < end && xp_isspace(*ptr)) ptr++;
                if (ptr >= end) return XP_NULL;

                s = ptr;
                while (ptr < end && !xp_isspace(*ptr)) ptr++;

                if (xp_strxcmp (s, ptr-s, word) == 0) return s;
        }
        while (ptr < end);

        return XP_NULL;
}

const xp_char_t* xp_strxcaseword (
	const xp_char_t* str, xp_size_t len, const xp_char_t* word)
{
        const xp_char_t* ptr = str;
        const xp_char_t* end = str + len;
        const xp_char_t* s;

        do
        {
                while (ptr < end && xp_isspace(*ptr)) ptr++;
                if (ptr >= end) return XP_NULL;

                s = ptr;
                while (ptr < end && !xp_isspace(*ptr)) ptr++;

                if (xp_strxcasecmp (s, ptr-s, word) == 0) return s;
        }
        while (ptr < end);

        return XP_NULL;
}

